@extends('admin.layout.common')
@section('content')
    <link rel="stylesheet" type="text/css" href="{{URL::asset('css/article/announcement.css')}}">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <div class="content">
        <h1 class="h1">公告列表</h1>
        <table border="1" width="100%">
            <thead>
            <tr>
                <th>ID</th>
                <th>发布范围</th>
                <th>发布内容</th>
                <th>发布时间</th>
                <th>操作</th>
            </tr>
            </thead>
            @foreach($list as $v)
            <tr id="datatable-responsive" class="id">
                <td>{{$v->id}}</td>
                <td>{{$v->department->name_cn}}</td>
                <td>{{$v->content}}</td>
                <td>{{$v->create_time}}</td>
                <td>
                    <input type="button" name="" value="编辑/查看" class="layui-btn layui-btn-radius layui-btn-primary" style="-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;" onclick="javascript:window.location.href='{{URL('admin/editArticle/'.$v->id)}}'">
                    @if($v->release_status==0)
                        <input type="button" name="" value="启用" class="layui-btn layui-btn-radius" style="-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;" onclick="enable({{$v->id}})">
                    @else
                        <input type="button" name="" value="禁用" class="jinyong" onclick="disable({{$v->id}})">
                    @endif
                    <input type="button" name="" value="删除" onclick="deleteArticle({{$v->id}})">
                </td>
            </tr>
            @endforeach
        </table>
        {{ $list->links()}}
    </div>
    <script>

        function enable($id) {
            layer.open({
                type: 2,
                area: ['500px', '300px'],
                content: 'http://{{$_SERVER['HTTP_HOST']}}/admin/release/2'
                , btn: ['确定', '取消']
                , yes: function (index, layero) {
                    $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/release/' + $id, function (data) {
                        location.reload();
                    })
                }
            })
        }
        function disable($id) {
            layer.open({
                type: 2,
                area: ['500px', '300px'],
                content: 'http://{{$_SERVER['HTTP_HOST']}}/admin/cancelRelease/3'
                , btn: ['确定', '取消']
                , yes: function (index, layero) {
                    $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/cancelRelease/' + $id, function (data) {
                        location.reload();
                    })
                }
            })
        }
        function deleteArticle($id) {
            layer.open({
                type: 2,
                area: ['500px', '300px'],
                content: 'http://{{$_SERVER['HTTP_HOST']}}/admin/deleteArticle/4'
                , btn: ['确定', '取消']
                , yes: function (index, layero) {
                    $.get('http://{{$_SERVER['HTTP_HOST']}}/admin/deleteArticle/' + $id, function (data) {
                        location.reload();
                    })
                }
            })
        }
</script>
@endsection

